<?php
require_once PATH_SITE.'cn/royan/php/utils/writers/WriterEvent.writer.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once PATH_SITE.'org/puremvc/php/patterns/command/SimpleCommand.php';
/**
 * Description of DispatchEventCommand
 *
 * @author yanr
 */
class DispatchEventCommand extends SimpleCommand
{
    //put your code here
    public function execute(INotification $notification)
    {
        $info = $notification->getBody();
        $eventInfo = array( "event"=>   $info["event"],
                            "code"=>    $info["code"],
                            "target"=>  $info["target"],
                            "data"=>    $info["data"] );
        $builderEvent = new BuilderEvent( $eventInfo );
        $writerEvent = new WriterEvent( $builderEvent->build()->getResult() );
        $message = $writerEvent->write();
        
        IF( is_array( $info["user"] ) )
        {
            $client = array();
            FOR( $i = 0; $i < count( $info["user"] ); $i++ )
                array_push( $client, $info["user"][$i]->__get("socket") );
        }
        ELSE{
            $client = $info["user"]->__get("socket");
        }
        
        $data = array( "client"=>       $client,
                       "message"=>      $message,
                       "cryptable"=>    TRUE );
        
        $this->sendNotification( ApplicationFacade::DISPATCH_CLIENT_DATA, $data );
    }
}

?>
